<html>
<head><meta charset="utf-8"><title>LTO not linking std? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/LTO.20not.20linking.20std.3F.html">LTO not linking std?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="156532568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/LTO%20not%20linking%20std%3F/near/156532568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/LTO.20not.20linking.20std.3F.html#156532568">(Jan 21 2019 at 12:20)</a>:</h4>
<p>When compiling a simple crate with LTO enabled, std doesn't get passed to the linker</p>



<a name="156532571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/LTO%20not%20linking%20std%3F/near/156532571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/LTO.20not.20linking.20std.3F.html#156532571">(Jan 21 2019 at 12:20)</a>:</h4>
<p>this seems weird to me?</p>



<a name="156532590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/LTO%20not%20linking%20std%3F/near/156532590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/LTO.20not.20linking.20std.3F.html#156532590">(Jan 21 2019 at 12:20)</a>:</h4>
<div class="codehilite"><pre><span></span>$ cargo new ltotest --bin
     Created binary (application) `ltotest` package
$ cd ltotest/
$ cargo rustc --release -- -C lto -Z print-link-args
   Compiling ltotest v0.1.0 (/tmp/ltotest)
&quot;cc&quot; &quot;-Wl,--as-needed&quot; &quot;-Wl,-z,noexecstack&quot; &quot;-m64&quot; &quot;-L&quot; &quot;~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib&quot; &quot;/tmp/ltotest/target/release/deps/ltotest-d6435de1c5152f8c.ltotest.ept6w7lf-cgu.0.rcgu.o&quot; &quot;-o&quot; &quot;/tmp/ltotest/target/release/deps/ltotest-d6435de1c5152f8c&quot; &quot;-Wl,--gc-sections&quot; &quot;-pie&quot; &quot;-Wl,-zrelro&quot; &quot;-Wl,-znow&quot; &quot;-Wl,-O1&quot; &quot;-nodefaultlibs&quot; &quot;-L&quot; &quot;/tmp/ltotest/target/release/deps&quot; &quot;-L&quot; &quot;~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib&quot; &quot;-Wl,--start-group&quot; &quot;-Wl,-Bstatic&quot; &quot;/tmp/rustcSoNfzg/libbacktrace_sys-6741d64f34191261.rlib&quot; &quot;-Wl,--end-group&quot; &quot;~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-c8174d577f7ebb97.rlib&quot; &quot;-Wl,-Bdynamic&quot; &quot;-ldl&quot; &quot;-lrt&quot; &quot;-lpthread&quot; &quot;-lgcc_s&quot; &quot;-lc&quot; &quot;-lm&quot; &quot;-lrt&quot; &quot;-lpthread&quot; &quot;-lutil&quot; &quot;-lutil&quot;
    Finished release [optimized] target(s) in 1.83s
</pre></div>



<a name="156532621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/LTO%20not%20linking%20std%3F/near/156532621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/LTO.20not.20linking.20std.3F.html#156532621">(Jan 21 2019 at 12:21)</a>:</h4>
<p>this is a problem for my custom target where I expect std to always be linked explicitly (so that certain global symbols are available for linking)</p>



<a name="156536531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/LTO%20not%20linking%20std%3F/near/156536531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/LTO.20not.20linking.20std.3F.html#156536531">(Jan 21 2019 at 13:35)</a>:</h4>
<p>is this <a href="https://github.com/rust-lang/rust/issues/37077" target="_blank" title="https://github.com/rust-lang/rust/issues/37077">https://github.com/rust-lang/rust/issues/37077</a> ?</p>



<a name="156537067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/LTO%20not%20linking%20std%3F/near/156537067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/LTO.20not.20linking.20std.3F.html#156537067">(Jan 21 2019 at 13:44)</a>:</h4>
<p>hmm maybe this is a difference between extern "C" and extern "Rust"</p>



<a name="156842235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/LTO%20not%20linking%20std%3F/near/156842235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mw <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/LTO.20not.20linking.20std.3F.html#156842235">(Jan 25 2019 at 10:12)</a>:</h4>
<p>if you do <code>-C lto</code> then <code>rustc</code> will do all the LTO work and only pass and already merged object file to the linker.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>